#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:rsa_01.py
@time:2022/03/14
"""
import json

import requests
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
from Crypto.Signature import PKCS1_v1_5 as Signature_pkcs1_v1_5
import base64




public_key = '''-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1xzCYtdu8bZEinh6Oh7/p+6xc
ilHgV/ChU3bZXyezLQqf6mzOnLH6GVZMMDafMw3uMtljWyECCqnECy2UhZPa5BFc
qA2xbYH8/WyKTraCRJT3Hn61UrI4Eac4YVxa1CJ8KaTQtIeZBoXHIW0r5XyhBwYe
NkSun+OFN+YBoJvCXwIDAQAB
-----END PUBLIC KEY-----'''


private_key = ''''''

def rsa_encrypt(message):
    """校验RSA加密 使用公钥进行加密"""
    cipher = Cipher_pkcs1_v1_5.new(RSA.importKey(public_key))
    cipher_text = base64.b64encode(cipher.encrypt(message.encode())).decode()
    return cipher_text


def rsa_decrypt(text):
    """校验RSA加密 使用私钥进行解密"""
    cipher = Cipher_pkcs1_v1_5.new(RSA.importKey(private_key))
    retval = cipher.decrypt(base64.b64decode(text), 'ERROR').decode('utf-8')
    return retval


def login():
    ...
    encry_text = rsa_encrypt("123456!")
    # encry_text = "EYLGGP/4g8rSjD0gsmuSZxBrCg+eacS3mnJI6yKgaNkNwpzbtemoj+tpNYj8IcEJ5mIr9deC6yt4EnsWejB7zgQxiBpAvGf+N3rzUDk/zldU1r98RFxtmPUN0hrV/wnTxuitTgl1MUk8x/EvmCA1AO43mdZoNLjreQ2rLfYKzCs="

    params = {
        "account": "lizhiqiao@uniontech.com",
        "captchaType": "1",
        "isCookie": False,
        "password": encry_text
    }

    """
    -H '' -H '' -H ': ' -H ': ' -H ': ' -H ': ' -H ': ' -H ': ' -H  -H ': ""' -H 'origin: https://cooperation.uniontech.com' -H ': ' -H 'sec-fetch-mode: ' -H 'referer: https://cooperation.uniontech.com/network' -H ''
    
    
    """
    headers = {
        # "Host": "cooperation.uniontech.com",
        "content-type":"application/json",
        "accept":"application/json, text/javascript, */*; q=0.01",
        # "x-requested-with":"XMLHttpRequest",
        "sec-ch-ua-platform":"macOS",
        "sec-fetch-site":"same-origin",
        "sec-fetch-mode":"cors",
        "sec-fetch-dest":"empty",
        "accept-language":"zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36",
        "referer":"https://cooperation.uniontech.com/network",
        "origin": "https://cooperation.uniontech.com"
    }
    session = requests.session()

    # session.get("http://www.baidu.com")
    # response = requests.post("https://cooperation.uniontech.com/wwwapi/Login/MDAccountLogin", data=json.dumps(params), headers=headers)
    # print(response.text)
    response = session.post("https://cooperation.uniontech.com/wwwapi/Login/MDAccountLogin",data=json.dumps(params),headers=headers)
    print(response.text)


if __name__ == '__main__':
    pass
    # print(rsa_encrypt("123456"))
    login()